package ee.homework.third;

import java.util.Random;
import ee.homework.first.Quicksort;

public class SortImpl {
	private Random random;

	public static void main(String[] args) {
		new SortImpl().run();
	}

	public void run() {
		HeapSort heapSort = new HeapSort();
		HeapSort2 heapSort2 = new HeapSort2();
		HeapSort3 heapSort3 = new HeapSort3();
		Quicksort quickSort = new Quicksort();
		random = new Random();
		for (int i = 0; i < 5; i++) {
			System.out.println("Cycle " + (i + 1));
			for (int k = 100; k <= 100000000; k *= 10) {
				int[] heapList = new int[k];
				int[] quickList = new int[k];
				int[] randomQuick = new int[k];
				int tmp;
				for (int j = 0; j < k; j++) {
					tmp = random.nextInt(k) + 1;
					heapList[j] = tmp;
					quickList[j] = tmp;
					randomQuick[j] = tmp;
				}
				System.out.println("Array length: 10e"
						+ (String.valueOf(k).length() - 1));

				long start = System.currentTimeMillis();
				heapSort3.sort(heapList);
				long end = System.currentTimeMillis();
				System.out.println("HeapSort took " + (end - start)
						+ " milliseconds.");

				long time = System.currentTimeMillis();
				quickSort.quickSort(quickList);
				System.out.println("QuickSort took "
						+ (System.currentTimeMillis() - time)
						+ " milliseconds.");
				time = System.currentTimeMillis();
				quickSort.randomizedQuickSort(randomQuick);
				System.out.println("Randomized quickSort took "
						+ (System.currentTimeMillis() - time)
						+ " milliseconds.");
				System.out.println();
			}
		}
	}
}
